package com.cszjzx.member.util;

import java.io.*;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.struts2.ServletActionContext;

import com.cszjzx.member.dao.DepartmentDAO;
import com.cszjzx.member.dao.DepartmentDAOImpl;
import com.cszjzx.member.dao.FieldDAO;
import com.cszjzx.member.dao.FieldDAOImpl;
import com.cszjzx.member.dao.MajorDAO;
import com.cszjzx.member.dao.MajorDAOImpl;
import com.cszjzx.member.dao.MemberDAOImpl;
import com.cszjzx.member.po.Department;
import com.cszjzx.member.po.Field;
import com.cszjzx.member.po.Major;
import com.cszjzx.member.po.Member;

public class ExcelUtilsDaoImpl implements ExcelUtilsDao {
	
	private int rowNum;
	private int cellNum;
	private List<Member> errors = new ArrayList<Member>();
	private FieldDAO fd = null;
	private DepartmentDAO dd = null;
	private MajorDAO md = null;
	private List<Major> majors = null;
	private static int CONTENT_START = 4;
	private static List<Department> departments = null;
	private static List<Field> fields = null;
	
	public ExcelUtilsDaoImpl() {
		try {
			fd = new FieldDAOImpl();
			dd = new DepartmentDAOImpl();
			md = new MajorDAOImpl();
			departments = dd.findAll();
			majors = md.findAll();
			fields = fd.findAll();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	@Override
	public List<Member> readMembersFromExcel(File file, int process) {
		String filename = file.getName();
		List<Member> result = null;
		if (filename.split("\\.")[1].equals("xls")) {
			result = readExcelXls(file, process);
		} else if (filename.split("\\.")[1].equals("xlsx")){
			result = readExcelXlsx(file, process);
		} else {
			return null;
		}
		return result;
	}
	
	@Override
	public String expMembersByFieldsToExcel(List<Member> members, List<String> fields, String filename) {
		//创建工作薄
		HSSFWorkbook workbook = null;
		HSSFSheet sheet = null;
		HSSFRow row = null;
		HSSFCell cell = null;
		List<Field> fList = new ArrayList<Field>();		//各阶段的字段列表综合
		List<Field> fs = null;							//存放临时的各阶段的字段列表
		int sumOfFields = 0;
		Map<String, Integer> isWrite = new HashMap<String,Integer>();	//是否写入的判定条件键值对
		String filepath = createMembersExcelTemplate(filename);
//		System.out.println("filepath:"+filepath);
		try {
			InputStream inputStream = new FileInputStream(new File(filepath));
			workbook = (HSSFWorkbook) WorkbookFactory.create(inputStream);
			sheet = workbook.getSheetAt(0);
			//获取各阶段的字段以及数量nationality
			for (int i = 1 ; i <= PROCESSES ; i ++) {
				fs = fd.findByStage(i);
				fList.addAll(fs);
				//第一阶段加上序号的列
				if (i == 1) {
					sumOfFields += (fs.size() + 1);
				} else {
					sumOfFields += fs.size();
				}
			}
			//创建是否写入的判定条件键值对
			for (int i = 0 ; i < fList.size() ; i ++) {
				isWrite.put(fList.get(i).getName(), 0);
			}
			for (int i = 0 ; i < fields.size() ; i ++) {
				isWrite.put(fields.get(i), 1);
//				System.out.println("fields: " + fields.get(i));
			}
			isWrite.put("序号", 1);
			
			//开始写入数据
			
			for (int i = 0 ; i < members.size() ; i ++) {
				Member member = members.get(i);
				row = sheet.createRow(CONTENT_START + i);
				//写入序号
				cell = row.createCell(0);
				cell.setCellValue(i + 1);
				System.out.println("写入序号" + (i + 1));
				//控制单元格格式
				HSSFCellStyle cellStyle = workbook.createCellStyle();
				cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);		//垂直居中
				cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);				//水平居中
				//写入Excel
				for (int j = 1 ; j < sumOfFields ; j ++) {
					
					if (isWrite.get(fList.get(j - 1).getName()) == 0) {
						continue;
					} else {
						cell = row.createCell(j);
						//设置自适应宽度
						sheet.autoSizeColumn(1, true);
						cell.setCellValue(member.getValue(fList.get(j-1).getName()));
						cell.setCellStyle(cellStyle);
//						System.out.println("写入对应字段： " + fList.get(j-1).getName() + " : " + member.getValue(fList.get(j-1).getName()));
					}
				}
			}
			inputStream.close();
			//写入文件excel
			File newExcel = new File(filepath);
		
			OutputStream os = new FileOutputStream(newExcel);
			workbook.write(os);
			os.close();
			
			
		} catch (EncryptedDocumentException e) {
			e.printStackTrace();
		} catch (InvalidFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			System.out.println("1");
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return filepath;
	}
	
	@Override
	public boolean hasErrors() {
		if (errors.size() == 0) {
			return false;
		} else {
			return true;
		}
	}

	@Override
	public List<Member> getErrorMembers() {
		return errors;
	}

	@SuppressWarnings("resource")
	@Override
	public String createMembersExcelTemplate(String filename) {
		
		File excel = new File(PATH_EXCEL + "excelTemplate\\" + filename);
		List<Field> fList = new ArrayList<Field>();		//各阶段的字段列表综合
		List<Field> fs = null;							//存放临时的各阶段的字段列表
		List<Integer> numOfFields = new ArrayList<Integer>();	//存放个阶段的数量 0开始
		int sumOfFields = 0;
		//如果文件名存在则删除
		if (excel.exists()) {
			excel.delete();
		} 
		try {
			HSSFWorkbook workbook = new HSSFWorkbook();
			HSSFSheet sheet = workbook.createSheet("团员信息表");
			HSSFRow row = null;
			HSSFCell cell = null;
			//获取各阶段的字段以及数量nationality
			for (int i = 1 ; i <= PROCESSES ; i ++) {
				fs = fd.findByStage(i);
				fList.addAll(fs);
				//第一阶段加上序号的列
				if (i == 1) {
					numOfFields.add(fs.size() + 1);
					sumOfFields += (fs.size() + 1);
				} else {
					numOfFields.add(fs.size());
					sumOfFields += fs.size();
				}
			}
			//生成前四栏，标题、阶段、字段序号、字段名
			//标题
			row = sheet.createRow(0);
			//样式控制
			HSSFCellStyle cellStyleTitle = workbook.createCellStyle();
			cellStyleTitle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);		//垂直居中
			cellStyleTitle.setAlignment(HSSFCellStyle.ALIGN_CENTER);				//水平居中
			//字体控制
			HSSFFont fontTitle = workbook.createFont();
			fontTitle.setFontHeightInPoints((short)16);
			fontTitle.setColor(HSSFFont.COLOR_RED);
			fontTitle.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
			//设置字体
			cellStyleTitle.setFont(fontTitle);
			
			sheet.addMergedRegion(new CellRangeAddress(0, 0, 0 , fList.size()));
			cell = row.createCell(0);
			cell.setCellValue("标题");
			cell.setCellStyle(cellStyleTitle);
			//阶段
			row = sheet.createRow(1);
			//阶段名称
			String[] processName = {"信息登记","团课及志愿者活动","填写团员材料","状态"};
			//样式控制
			HSSFCellStyle cellStyleStage = workbook.createCellStyle();
			cellStyleStage.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);		//垂直居中
			cellStyleStage.setAlignment(HSSFCellStyle.ALIGN_CENTER);				//水平居中
			//字体控制
			HSSFFont fontStage = workbook.createFont();
			fontStage.setFontHeightInPoints((short)12);
			fontStage.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
			//设置字体
			cellStyleStage.setFont(fontStage);
			int pos = 0;//起始偏移点
			for (int i = 0 ; i < PROCESSES ; i ++) {
				//合并单元格，参数为：（起始行，结束行，起始列，结束列）
				sheet.addMergedRegion(new CellRangeAddress(1 , 1 , pos , pos + numOfFields.get(i) - 1));
				//创建单元格
				cell = row.createCell(pos);
				cell.setCellValue(processName[i]);
				cell.setCellStyle(cellStyleStage);
				pos += numOfFields.get(i);
			}
			//字段序号
			row = sheet.createRow(2);
			//样式控制
			HSSFCellStyle cellStyleNormal = workbook.createCellStyle();
			cellStyleNormal.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);		//垂直居中
			cellStyleNormal.setAlignment(HSSFCellStyle.ALIGN_CENTER);				//水平居中
			//字体控制
			HSSFFont fontNormal = workbook.createFont();
			fontNormal.setFontHeightInPoints((short)10);
			fontNormal.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
			cellStyleNormal.setFont(fontNormal);
			//字段序号生成
			for (int i = 0 ; i < sumOfFields ; i ++) {
				if (i == 0) {
					cell = row.createCell(i);
					cell.setCellValue("入团流程");
					cell.setCellStyle(cellStyleNormal);
				} else {
					cell = row.createCell(i);
					cell.setCellValue(i);
					cell.setCellStyle(cellStyleNormal);
				}
			}
			//字段名
			row = sheet.createRow(3);
			for (int i = 0 ; i < sumOfFields ; i ++) {
				if (i == 0) {
					cell = row.createCell(i);
					cell.setCellValue("序号");
					cell.setCellStyle(cellStyleNormal);
				} else {
					cell = row.createCell(i);
					//设置单元格宽度
					sheet.setColumnWidth(i, fList.get(i-1).getChinese().getBytes().length*256);
					cell.setCellValue(fList.get(i-1).getChinese());
					cell.setCellStyle(cellStyleNormal);
				}
			}
			//写入文件excel
			excel.createNewFile();
			OutputStream os = new FileOutputStream(excel);
			workbook.write(os);
			os.close();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (EncryptedDocumentException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
			
		return PATH_EXCEL + "excelTemplate\\" + filename;
	}

	/**
	 * 读取97-03的excel（xls）
	 * @param file
	 * @param process
	 * @return
	 */
	private List<Member> readExcelXls(File file, int process) {
		List<Member> result = null;
		List<String> chName = new ArrayList<String>();
		HSSFWorkbook workbook = null;
		HSSFSheet sheet = null;
		HSSFRow row = null;
		HSSFCell cell = null;
		int idCardPos = -1;
		try {
			//获得excel对象
			workbook = (HSSFWorkbook) WorkbookFactory.create(file);
			
			//获得表的数量
			//int sheetNum = workbook.getNumberOfSheets();
			int sheetNum = 1;
			for (int i = 0 ; i < sheetNum ; i ++) {
				//获得表对象
				sheet = workbook.getSheetAt(i);
				//获得行数
				rowNum = sheet.getLastRowNum() + 1;
				//判断sheet表是否为空
				if (sheet.getFirstRowNum() == rowNum) {
					continue;
				}
				//获得列数
				cellNum = sheet.getRow(0).getLastCellNum();
				//初始化list
				result = new ArrayList<Member>();
				
				//列名所在行 ： chnamePos
				row = sheet.getRow(CONTENT_START - 1);
				//存下列名，并找出身份证所在列
				for (int a = 0 ; a < cellNum ; a ++) {
					cell = row.getCell(a);
					chName.add(cell.getStringCellValue());
					if (chName.get(a).equals("身份证号")) {
						idCardPos = a;
					}
				}
				
				//从第 chnamePos + 1 行开始读，跳过标题
				for (int j = sheet.getFirstRowNum() + CONTENT_START ; j < rowNum ; j ++){
                    //获取当前行
                    row = sheet.getRow(j);
                    
                    //如果当前行为空，或者是 身份证号那一栏 (idCardPos) 为空，就跳过
                    if (row == null || row.getCell(idCardPos).getCellType() == HSSFCell.CELL_TYPE_BLANK){
                        continue;
                    }
                    
                    Member member = new Member();
                    member.setValue("阶段", String.valueOf(process));
                    //读取单元格
                    for (int k = row.getFirstCellNum() ; k < cellNum ; k ++){
                        //获取当前单元格
                        cell = row.getCell(k);
                        //列为序号，不存
                        if (chName.get(k).equals("序号")) {
                        	continue;
                        }
//                        System.out.println(chName.get(k));
                        //若当前单元格为空则跳过
                        if (cell != null) {
                            //当前单元格不为空，判断当前单元格内容的类型
                            switch (cell.getCellType()) {
                                case HSSFCell.CELL_TYPE_BLANK:
                                    member.setValue(chName.get(k), "");
                                    break;

                                case HSSFCell.CELL_TYPE_STRING:
                                    member.setValue(chName.get(k), cell.toString());
                                    break;

                                case HSSFCell.CELL_TYPE_NUMERIC:
                                    //判断是否是日期类型
                                    if (DateUtil.isCellDateFormatted(cell)){
                                        Date date = cell.getDateCellValue();
                                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                                        member.setValue(chName.get(k), sdf.format(date));
                                    } else {
                                        //不是，将double类型转换成String类型
                                        //格式化，防止浮点数过大显示为科学计数法
                                        DecimalFormat df = new DecimalFormat("#");
                                        member.setValue(chName.get(k), String.valueOf(df.format(cell.getNumericCellValue())));
                                    }
                                    break;

                                case HSSFCell.CELL_TYPE_BOOLEAN:
                                	member.setValue(chName.get(k), String.valueOf(cell.getBooleanCellValue()) );
                                    break;

                                case HSSFCell.CELL_TYPE_FORMULA:
                                	try {
                                		member.setValue(chName.get(k), String.valueOf(cell.getNumericCellValue()) );
                                	} catch (IllegalStateException e) {
                                		member.setValue(chName.get(k), String.valueOf(cell.getRichStringCellValue()) );
                                	}
                                    break;

                                default: break;
                            }
                        } else {
                        	member.setValue(chName.get(k), "");
                        }
                    }
                    //检验member是否合格
                    if (!checkMember(member, process)) {
                    	errors.add(member);
                    }
                    result.add(member);
                }
			}
		} catch (FileNotFoundException e) {
//			System.out.print("文件不存在");
			e.printStackTrace();
		} catch (EncryptedDocumentException e) {
			e.printStackTrace();
		} catch (InvalidFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return result;
	}
	
	/**
	 * 读取07-*的excel（xlsx）
	 * @param file
	 * @param process
	 * @return
	 */
	private List<Member> readExcelXlsx(File file, int process) {
		List<Member> result = null;
		List<String> chName = new ArrayList<String>();
		XSSFWorkbook workbook = null;
		XSSFSheet sheet = null;
		XSSFRow row = null;
		XSSFCell cell = null;
		int idCardPos = -1;
		try {
			//获得excel对象
			workbook = (XSSFWorkbook) WorkbookFactory.create(file);
			
			//获得表的数量
			//int sheetNum = workbook.getNumberOfSheets();
			int sheetNum = 1;
			for (int i = 0 ; i < sheetNum ; i ++) {
				//获得表对象
				sheet = workbook.getSheetAt(i);
				//获得行数
				rowNum = sheet.getLastRowNum() + 1;
				//判断sheet表是否为空
				if (sheet.getFirstRowNum() == rowNum) {
					continue;
				}
				//获得列数
				cellNum = sheet.getRow(0).getLastCellNum();
				//初始化list
				result = new ArrayList<Member>();
				
				//列名所在行 ： chnamePos
				row = sheet.getRow(CONTENT_START - 1);
				//存下列名，并找出身份证所在列
				for (int a = 0 ; a < cellNum ; a ++) {
					cell = row.getCell(a);
					chName.add(cell.getStringCellValue());
					if (chName.get(a).equals("身份证号")) {
						idCardPos = a;
					}
				}
				
				//从第 chnamePos + 1 行开始读，跳过标题
				for (int j = sheet.getFirstRowNum() + CONTENT_START ; j < rowNum ; j ++){
                    //获取当前行
                    row = sheet.getRow(j);
                    
                    //如果当前行为空，或者是 身份证号那一栏 (idCardPos) 为空，就跳过
                    if (row == null || row.getCell(idCardPos).getCellType() == HSSFCell.CELL_TYPE_BLANK){
                        continue;
                    }
                    
                    Member member = new Member();
                    member.setValue("阶段", String.valueOf(process));
                    //读取单元格
                    for (int k = row.getFirstCellNum() ; k < cellNum ; k ++){
                        //获取当前单元格
                        cell = row.getCell(k);
                        //列为序号，不存
                        if (chName.get(k).equals("序号")) {
                        	continue;
                        }
//                        System.out.println(chName.get(k));
                        //若当前单元格为空则跳过
                        if (cell != null) {
                            //当前单元格不为空，判断当前单元格内容的类型
                            switch (cell.getCellType()) {
                                case XSSFCell.CELL_TYPE_BLANK:
                                    member.setValue(chName.get(k), "");
                                    break;

                                case XSSFCell.CELL_TYPE_STRING:
                                    member.setValue(chName.get(k), cell.toString());
                                    break;

                                case XSSFCell.CELL_TYPE_NUMERIC:
                                    //判断是否是日期类型
                                    if (DateUtil.isCellDateFormatted(cell)){
                                        Date date = cell.getDateCellValue();
                                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                                        member.setValue(chName.get(k), sdf.format(date));
                                    } else {
                                        //不是，将double类型转换成String类型
                                        //格式化，防止浮点数过大显示为科学计数法
                                        DecimalFormat df = new DecimalFormat("#");
                                        member.setValue(chName.get(k), String.valueOf(df.format(cell.getNumericCellValue())));
                                    }
                                    break;

                                case XSSFCell.CELL_TYPE_BOOLEAN:
                                	member.setValue(chName.get(k), String.valueOf(cell.getBooleanCellValue()) );
                                    break;

                                case XSSFCell.CELL_TYPE_FORMULA:
                                	try {
                                		member.setValue(chName.get(k), String.valueOf(cell.getNumericCellValue()) );
                                	} catch (IllegalStateException e) {
                                		member.setValue(chName.get(k), String.valueOf(cell.getRichStringCellValue()) );
                                	}
                                    break;

                                default: break;
                            }
                        } else {
                        	member.setValue(chName.get(k), "");
                        }
                    }
                    //检验member是否合格
                    if (!checkMember(member, process)) {
                    	errors.add(member);
                    }
                    result.add(member);
                }
			}
		} catch (FileNotFoundException e) {
//			System.out.print("文件不存在");
			e.printStackTrace();
		} catch (EncryptedDocumentException e) {
			e.printStackTrace();
		} catch (InvalidFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return result;
	}

	/**
	 * 检验member数据是否正确
	 * @param member
	 * @param process
	 * @return
	 */
	private boolean checkMember(Member member, int process) {
		//判断系班是否存在
		if ( !hasDepAndMaj(member.getValue("department"), member.getValue("major")) ) {
			return false;
		} else {
			if (process < 0) {
				//判断老团员数据是否正确
				return isValidOldMember(member);
			} else {
				//判断新团员该阶段数据是否正确
				return isValidNewMember(member, process);
			}
		}
	}
	
	/**
	 * 检验老团员数据是否合格(若有默认值的字段对应的 member中的值为空 或者 member中的值不等于默认值 ，返回false)
	 * @param member
	 * @return
	 */
	private boolean isValidOldMember(Member member) {
		try {
			//获取所有的字段
			fields = fd.findAll();
			for (int i = 0 ; i < fields.size() ; i ++) {
				//判断字段是否有默认值，如果没有默认值就跳过
				if (fields.get(i).getDefaultValue() == null) {
					continue;
				} else {
					
					if (member.getValue(Member.name[i]) == null) {
						//字段有默认值，若member对应字段为null，则记录不合格
						return false;
					} else if (member.getValue(Member.name[i]).equals(fields.get(i).getDefaultValue())) {
						//字段有默认值，member对应字段的value和默认值进行比较，相等就跳过
						continue;
					} else {
						//不等表示该记录不合格，返回false
						return false;
					}
				}
			}
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return true;
	}
	
	/**
	 * 检验新团员数据是否合格
	 * @param member
	 * @param process >= 0
	 * @return
	 */
	private boolean isValidNewMember(Member member, int process) {
		try {
			//获取该阶段的所有字段
			fields = fd.findByStage(process);
			//判断member中该阶段的数据有没有空的
			for (int i = 0; i < fields.size(); i ++) {
				//如果对应字段的内容是null或者是 "" 空字符串,返回false
				if (member.getValue(fields.get(i).getName()) == null || member.getValue(fields.get(i).getName()).equals("")){
					return false;
				}
			}
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return true;
	}
	
	/**
	 * 判断是否存在系，班
	 * @param dep 系名
	 * @param maj 班名
	 * @return
	 */
	private boolean hasDepAndMaj(String dep, String maj) {
		if (departments.contains(dep) && majors.contains(maj)) {
			return true;
		} else {
			return false;
		}
	}
	
	public static void main(String[] args) throws ClassNotFoundException, SQLException, IOException {
//		System.out.println("Member实例化之前的静态变量: ");
//		System.out.println("Member中的mapChinese: " + Member.mapChinese.size());
//		System.out.println("Member中的mapEnglish: " + Member.mapEnglish.size());
//		if (Member.name == null) {
//			System.out.println("name = Null");
//		} else {
//			System.out.println("Member中的name: " + Member.name.length);
//		}
//		Member member = new Member();
//		System.out.println("Member实例化之后的静态变量: ");
//		System.out.println("Member中的mapChinese: " + Member.mapChinese.size());
//		System.out.println("Member中的mapEnglish: " + Member.mapEnglish.size());
//		System.out.println("Member中的name: " + Member.name.length);
		ExcelUtilsDaoImpl eud = new ExcelUtilsDaoImpl();
//		File file = new File("/home/vliupro/xls-test.xls");
//		List<Member> members = eud.readMembersFromExcel(file, -1);
//		System.out.println("所有数据：" + "\t数量：" + members.size());
//		for (Member member : members) {
//			System.out.println(member.toString());
//		}
//		System.out.println("错误数据：" + "\t数量：" + eud.errors.size());
//		for (Member member : eud.errors) {
//			System.out.println(member.toString());
//		}
//		System.out.println("导出Excel模板-----");
//		String filename = "11.xls";
//		filename = eud.createMembersExcelTemplate(filename);
//		System.out.println("导出" + filename + "成功");
		System.out.println("导出团员信息...");
		List<Member> members = new MemberDAOImpl().findByDepartmentNameAndProcess("传媒系", "2");
		for (Member member : members) {
			System.out.println(member);
		}
		List<String> name = new ArrayList<String>();
		name.add("姓名");
		name.add("性别");
		name.add("身份证号");
		name.add("团课情况");
		name.add("入团时间");
		String path = eud.expMembersByFieldsToExcel(members, name, "11.xls");
		System.out.println("导出 " + path + " 成功");
	}
	
	private String getPath(){
		String path = ServletActionContext.getServletContext().getRealPath("/");
		//String path = "E:\\";
		return path;
	}
	
	//文件存放路径(Linux下)
	//public static final String PATH_EXCEL = "/home/vliupro/";
	//文件存放路径(Windows下)
	public static final String PATH_EXCEL = new ExcelUtilsDaoImpl().getPath();
	//阶段数
	public static final int PROCESSES = 4;
}
